﻿using System;
using System.Windows.Forms;
using BLLayer;
using Button = ESRI.ArcGIS.Desktop.AddIns.Button;

namespace LabelForDem
{
    public class LabelSource : Button
    {
        protected override void OnClick()
        {
            try
            {
                var layer = ArcScene.Document.SelectedLayer;
                if (layer == null)
                    throw new Exception("请选择要添加标注的图层");
                var layerName = layer.Name;
                var manager = Label3DManager.GetManager();
                var elements = manager[layerName];
                if (elements == null)
                {
                    elements = manager.Add(layerName);
                }
                else
                {
                    var result = MessageBox.Show("是否重新添加标注？", "添加标注", MessageBoxButtons.YesNo);
                    if (result == DialogResult.Yes)
                    {
                        GraphicsContainer.Delete3DText(elements);
                        elements = manager.Update(layerName);
                    }
                }
                GraphicsContainer.Draw3DText(elements);
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
        }

        protected override void OnUpdate()
        {
            Enabled = ArcScene.Application != null;
        }
    }
}